import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5

# 公钥加密
# 输入加密数据
msg = 'admin'

# 读取公钥
read = open('public.pem').read()
public_key = RSA.import_key(read)
# 生成加密对象
pk = PKCS1_v1_5.new(public_key)
# 加密
pk_text = pk.encrypt(msg.encode())
# 通过base64进行编码
result = base64.b64encode(pk_text)
print(result)
